package server

import (
	"context"
	"fmt"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/const"
	"longmen/server/pkg/db/mysql/db_sports"
	pb "longmen/server/pkg/protobuf"
)

func (s *SportServer) MatchLiveUrl(ctx context.Context, req *pb.MatchLiveUrlReq) (*pb.MatchLiveUrlResp, error) {
	var resp pb.MatchLiveUrlResp
	url := db_sports.GetMatchLiveUrl(global.Sport(), req.Home, req.Away)
	if len(url) > 1 {
		resp.LiveUrl = url
		resp.UrlType = 1 //视频
	} else {
		matchId := db_sports.GetMatchId(global.Sport(), req.Home, req.Away)
		if matchId > 0 {
			if req.GetMatchType() == 1 {
				resp.LiveUrl = fmt.Sprintf(_const.FootBallAnimationUrl, matchId)
			} else {
				if req.GetPlatform() == _const.LOGIN_PLATFORM_IOS || req.GetPlatform() == _const.LOGIN_PLATFORM_ANDROID {
					resp.LiveUrl = fmt.Sprintf(_const.BasketBallAnimationAppUrl, matchId)
				} else {
					resp.LiveUrl = fmt.Sprintf(_const.BasketBallAnimationUrl, matchId)
				}
			}
			resp.UrlType = 2 //动画
		}
	}
	return &resp, nil
}
